import { list } from '@neu/cmdb-ui/api/datatype'
import { list as relationtypeList } from '@neu/cmdb-ui/api/relationtype'

const state = {
  datatypes: [],
  relationtypes: []
}

const mutations = {
  SET_DATATYPES: (state, datatypes) => {
    state.datatypes = datatypes
  },
  SET_RELATIONTYPES: (state, relationtypes) => {
    state.relationtypes = relationtypes
  }
}

const actions = {
  loadDatatypes({ commit }) {
    list().then(response => {
      commit('SET_DATATYPES', response.data)
    })
  },
  loadRelationtypes({ commit }) {
    relationtypeList().then(response => {
      commit('SET_RELATIONTYPES', response.data)
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
